package com.lam.mall.api.common.config;

import javax.sql.DataSource;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alibaba.druid.pool.DruidDataSource;
import com.lam.framework.datasource.DataSourceMap;
import com.lam.framework.datasource.config.BaseDynamicDataSource;
import com.lam.framework.datasource.model.DynamicDataSourceMap;

/**
 * @author lam
 *
 */
@Configuration  
public class DynamicDataSourceConfig extends BaseDynamicDataSource{

	@Bean
	@Override
	public DataSourceMap createDataSourceMap(){
		return DynamicDataSourceMap
				.create(DsType.MASTER)
				;
	}
	
	@Bean(name = DsType.MASTER + DS_SUFFIX)
    @ConfigurationProperties(prefix = "datasource.master")   
    public DataSource masterDataSource() {
		return setEvictableIdleTime(new DruidDataSource());
    }
	
}
